Skip to content

feat: add string.isbn keyword for ISBN validation#1622

Open
Ojoxux wants to merge 1 commit into
arktypeio:mainfrom
Ojoxux:ojoxux/add-isbn-validation
Open

feat: add string.isbn keyword for ISBN validation#1622
Ojoxux wants to merge 1 commit into
arktypeio:mainfrom
Ojoxux:ojoxux/add-isbn-validation

Conversation

@Ojoxux
Copy link
Copy Markdown

@Ojoxux Ojoxux commented May 28, 2026

Summary

Following the precedent set by string.creditCard, this PR introduces string.isbn as a built-in validator.

I've encountered the need for this in my own projects before, where I ended up relying on custom validation.

Validating ISBNs requires more than a simple format check, since ISBN-10 and ISBN-13 use distinct checksum algorithms:

As a result, rolling a custom implementation with narrow can be easy to get subtly wrong.

Behavior:

  • Accepts ISBN-10 or ISBN-13
  • Allows hyphen/space separators, which are stripped before validation
  • Validates the appropriate checksum
  • Rejects lowercase x as a check digit

Examples:

Input Result
"978-4-87311-873-4" ✅ valid
"4-87311-873-5" ✅ valid
"020530902X" ✅ valid
"9784873118735" ❌ invalid checksum
"020530902x" ❌ invalid

Implementation notes:

  • Adds the validator in ark/type/keywords/string.ts
  • Exposes it via rootSchema({ domain: "string", predicate: ... })
  • Registers it in Scope.module
  • Adds the corresponding namespace $ type

Test plan

  • Valid ISBN-10 and ISBN-13 inputs are accepted, with and without separators
  • Invalid checksum, lowercase x, wrong length, and non-digit input are rejected
  • pnpm prChecks passes

@github-project-automation github-project-automation Bot moved this to To do in arktypeio May 28, 2026
@Ojoxux Ojoxux changed the title feat: add string.isbn keyword for ISBN-10 / ISBN-13 validation feat: add string.isbn keyword for ISBN validation May 28, 2026
@Ojoxux Ojoxux marked this pull request as ready for review June 6, 2026 13:24
Copy link
Copy Markdown
Contributor

@pullfrog pullfrog Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — adds string.isbn as a built-in keyword for ISBN-10 and ISBN-13 validation with checksum verification, following the same patterns as string.creditCard.

  • Add isbn keyword with isIsbn10 / isIsbn13 checksum helpers — validates ISBN-10 (modulo-11, X check digit) and ISBN-13 (alternating 1/3 weight sum modulo-10), stripping hyphens and spaces before validation.
  • Register isbn in Scope.module and namespace type — wired into the string keyword set alongside creditCard, email, etc., with isbn: string in the $ namespace type.
  • Add unit tests for valid/invalid ISBNs — covers valid ISBN-10, ISBN-13, hyphen/space separators, X check digit, invalid checksums, lowercase x, wrong length, and non-digit input.
  • Add string.isbn entry to integration allConfig — includes the new keyword in the configuration test fixture.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To do

Development

Successfully merging this pull request may close these issues.

1 participant